<?php

namespace app\store\controller\data;

use app\store\controller\Controller;
use app\store\model\store\Shop as ShopModel;

class Shop extends Controller
{
    /* @var ShopModel $model */
    private $model;

    /**
     * 构造方法
     * @throws \app\common\exception\BaseException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new ShopModel;
        $this->view->engine->layout(false);
    }

    /**
     * 门店列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function lists()
    {
        $list = $this->model->getLists($this->request->get());

        $da = explode('=', $this->request->request()['s']);

        $_SESSION['goods_id'] = $da[1];
//        $shop= new  \app\common\model\store\Shop();
//        $list = collection($shop->manba())->toArray();

        return $this->fetch('list', compact('list'));
    }

    /**
     * 门店列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function data()
    {
        $data = input();


        foreach ($data['data'] as $k => $v) {
            if (db('stock')->where('id', $v['stock_id'])->find()) {
                db('stock')->where('id', $v['stock_id'])->update([
                    'stock' => $v['stock']
                ]);
            } else {
                db('stock')->insert([
                    'shop_id' => $v['shop_id'],
                    'goods_id' => $data['goods_id'],
                    'stock' => $v['stock'],
                    'wxapp_id' => 10001
                ]);
            }

        };
        exit;


    }


    public function acvt($search=''){


        $da = explode('=', $this->request->request()['s']);

        $data = $da[1];

        // 店员列表
        $model = new \app\store\model\activity\Manba1();
        $list =$model->getList($search,$data);

        // 门店列表
        $shopList = [];

        return $this->fetch('acvt', compact('list', 'shopList'));

    }
}